<?php
    /* @author huangchuting
     * @time 2020.6.6 
     * 对点赞操作后台操作
     * 
     * */
  
    header("Content-type:text/html;charset=utf-8");
    require_once '../inc/review.php';
    @$current_user=$_SESSION["CURRENT_USER"];
    $reviewId=$_POST["reviewId"];
    $message="";
    $show="";
    if (isset($current_user)) 
    {
        if(isset($_POST["uId"]))
        {
            $uId=$_POST["uId"];
            $rs1=downGood($reviewId);
            $re2=deleteZan($uId, $reviewId);
            $review=getReviewId($reviewId);
            $good=$review["good"];
            $show.=<<<html
            
        <button id="donolike" onclick="zan()"></button>
		<span id="zan">$good</span>
html;
            
        }
        else
        {
            
            $uId=$current_user["uId"];
            $zan=getReviewZanUId($reviewId, $uId);
            if (!empty($zan)) {
                $rs1=downGood($reviewId);
                $re2=deleteZan($uId, $reviewId);
                $review=getReviewId($reviewId);
                $good=$review["good"];
                $show.=<<<html
                
        <button id="donolike" onclick="zan()"></button>
		<span id="zan">$good</span>
html;
            }else
            {
                $rs1=addZan($reviewId, $uId);
                $rs2=upGood($reviewId);
                $review=getReviewId($reviewId);
                $good=$review["good"];
                $show.=<<<html
		<button id="dolike" onclick="zanDel()"></button>
		<span id="zan">$good</span>
html;
            }
            
        }
        echo $show;
    }
    else 
    {
        echo "<script language='JavaScript'>;alert('用户暂未登录，不能点赞');window.location.href='../style/review.php?reviewId=$reviewId';</script>";
      
    }
    
?>